home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 September / PCWorld_2008-09_cd.bin / v cisle / sadanastroju / IE7proSetup_2.3.exe / userscripts / GoogleImagesNF.ieuser.js < prev    next >
Text File  |  2007-11-20  |  2KB  |  84 lines

  1. // Copyright (c) 2007 ie7pro@gmail.com
  2. // Copyright (c) 2005 trixiedev@gmail.com
  3. // This script is licensed under the MIT license.  See
  4. // http://opensource.org/licenses/mit-license.php for more details.
  5. //
  6. // ==UserScript==
  7. // @name          Google Images NoFrame link
  8. // @namespace     http://iescripts.org/
  9. // @description      Adds a noframe link to images in Google Images search results
  10. // @include       http://images.google.*/*
  11. // ==/UserScript==
  12.  
  13. //
  14. // IE7pro Script, ported from
  15. //      Discussion forum: http://groups.yahoo.com/group/trixieUsers/
  16. //
  17.  
  18. (function() 
  19. {
  20.  
  21.     function GetImageUrl(theUrl)
  22.     {
  23.         if (theUrl == null)
  24.             return(false);
  25.  
  26.         // Looking for "imgurl=..."
  27.         var searchStr = "imgurl=";
  28.         var pos = theUrl.indexOf(searchStr);
  29.         var temp = null;
  30.  
  31.         if (pos >= 0){
  32.                 temp = theUrl.substring(pos + searchStr.length);
  33.             var p = temp.indexOf('&imgrefurl=');
  34.             if(p != -1){
  35.                 temp = temp.substr(0, p);
  36.             }
  37.         }
  38.         
  39.         return temp;
  40.     }
  41.     
  42.     function MakeNoFrameLink(url)
  43.     {
  44.         if (url != null && url.length > 0)
  45.         {
  46.             var container = document.createElement("span");
  47.             container.appendChild(document.createTextNode(" "));
  48.             
  49.             var newLink = document.createElement("a");
  50.             newLink.setAttribute("href", url);
  51.             newLink.setAttribute("target", "_blank");
  52.             newLink.appendChild(document.createTextNode("[nf]"));
  53.             container.appendChild(newLink);
  54.             
  55.             return container;
  56.         }
  57.         
  58.         return null;
  59.     }
  60.  
  61.     var hyperlinks = document.getElementsByTagName("a");
  62.     //PRO_log("enter");
  63.  
  64.     for (var i = 0; i < hyperlinks.length; ++i)
  65.     {
  66.         var node = hyperlinks[i];
  67.         var href = node.getAttribute("href");
  68.  
  69.         var imgUrl = GetImageUrl(href);
  70.         if (imgUrl != null)
  71.         {
  72.             var link = MakeNoFrameLink(imgUrl);
  73.             
  74.             if (link != null)
  75.             {
  76.                 if (node.nextSibling == null)
  77.                     node.parentNode.appendChild(link);
  78.                 else
  79.                     node.parentNode.insertBefore(link, node.nextSibling);
  80.             }
  81.         }
  82.     }
  83. })();
  84.